
import { useTranslation } from 'react-i18next'
import { Link, useNavigate } from "react-router-dom";
import HeaderTitle from "../login/header";
import style from "./index.module.less"
import { EyeInvisibleOutline, EyeOutline } from "antd-mobile-icons"
import React, { Fragment, useState ,useEffect} from 'react'
import {
	Form,
	Input,
	Checkbox,
	Button,
	Toast,

} from 'antd-mobile'
import { getgamelist,user_gamelogin } from "@/apis/user.js"
import {LeftOutline} from "antd-mobile-icons"

import toptag from "../../static/top-tag.png"

const Promotionlist = (props) => {
	const BASE_URL = import.meta.env.VITE_BASE_URL;
	const [flag, setFlag] = useState(false);
	const [activitylist,setActivitylist] = useState([]);
	const navigate = useNavigate()
	useEffect(() => {
		console.log("初始化----优惠活动");
		// setFlag(true);
		let proCode = localStorage.getItem('proCode')
		let code = localStorage.getItem('code')
		let gameType = localStorage.getItem('gameType')
		getgamelist({
			product_type:proCode,
			code:code,
			game_type:gameType
		}).then(res => {
		
			if (res.status == 0) {
				setActivitylist(res.games)
	
			}
		})
		setTimeout(()=>{
			if (window.scrollTo) {
				window.scrollTo(0, 0);
			} else if (document.body.scrollTop) {
				document.body.scrollTop = 0;
			} else {
				document.documentElement.scrollTop = 0;
			}
			document.getElementById('root').scrollIntoView(true);
			document.getElementById('body').scrollIntoView(true);
		},0)
		return ()=>{console.log('初始化----个人中心')}
	  }, []);
	  const backFun = ()=>{
	    navigate(-1);
	  }
	  const godetail = (e) =>{
		  let token =  localStorage.getItem('token')
		  Toast.show({
		  	icon: 'loading',
		  	content: t('login.title53'),
		  })
		//   user_gamelogin({
		//   	product_type:e.productType,
		//   	code:e.productCode,
		//   	game_type:e.gameType,
		//   	gameCode:e.tcgGameCode,
		//   	devices:1,
		//   	token:token,
		//   	language:localStorage.getItem('lang')
		//   }).then(res => {
		//   	if (res.code == 200) {
		//   		window.open(res.gameUrl)
		//   		Toast.clear()
		//   	}else{
		//   		Toast.clear()
		//   		message.error(res.msg)
		//   	}
		//   })
		  window.open('/m/game/login?product_type=' + e.productType + '&game_type=' + '&gameCode='+ e.tcgGameCode + '&devices=1' + '&token=' + token + '&code=' + e.productCode + '&language=' + localStorage.getItem('lang'))
	
		}
	  const { t } = useTranslation();
	return (
		<React.Fragment>
			<div className={style['newadd']}>
				<div className={style['header-title']}>
					<div className={style['right']} onClick={() => backFun()}>
						<LeftOutline style={{cursor:'pointer'}} className={ style['icon']}  />
					</div>
					<div className={style['title']}>游戏列表</div>
					<div className={style['right']} onClick={() => backFun()}>首页</div>
				</div>
				<div className={style['glmain']}>
					<div className={style['glmainbox']}>
						<div className={style['gmmbheader']}>
							<div className={style['gmmbhtext']}>ALL Game</div>
							<div className={style['gmmbhline']}></div>
						</div>
						<div className={style['gmmbcon']}>
							{activitylist.length > 0 && (
								activitylist.map((item,index)=>{
								return (
									<div className={style['gmmbitem']} key={index} onClick={() => godetail(item)}>
										{
											item.image ? (<img className={style['gmmbilogo']} src={item.image} alt="" />) : (<img className={style['gmmbilogo']} src={"https://images.b51613.com:42666/TCG_GAME_ICONS/"+item.productCode +"/"+ item.tcgGameCode+".png"} alt="" />)
										}
										<div className={style['gmmbitext']}>{item.gameName}</div>
										<img className={style['gmmbiicon']} src={toptag} alt="" />
									</div>
								);
								})
							)}
						</div>
					</div>
				</div>
			</div>
		</React.Fragment>
	)
}


export default Promotionlist
